package com.example.shixunandjavagotoyangchen.BoosYang.Day002;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.modelviewpresenter.View.BasterFragment;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1106.ClothingmatchingAdpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1106.ClothingmatchingBean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1106.ClothingmatchingContion;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1106.ClothingmatchingModel;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1106.ClothingmatchingPresenter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1107.PackageAdpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1107.PackageBean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1107.PackageContion;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1107.PackageModel;
import com.example.shixunandjavagotoyangchen.BoosYang.Day002.Day002_1107.PackagePresenter;
import com.example.shixunandjavagotoyangchen.R;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.List;


public class BlankFragmentDay002_1106 extends BasterFragment  implements OnRefreshLoadMoreListener, ClothingmatchingContion.vier  {


    public static SmartRefreshLayout ClothingmatchingSmartRefreshLayout;
    private RecyclerView ClothingmatchingRecyclerView;
    public boolean issdd= true;
    public ClothingmatchingAdpter adpter;
    public ClothingmatchingPresenter presenter;

    @Override
    public int BandLayout() {
        return R.layout.fragment_blank_fragment_day002_1106;
    }

    @Override
    public void initView() {

        ClothingmatchingSmartRefreshLayout = (SmartRefreshLayout) findViewById(R.id.Clothingmatching_SmartRefreshLayout);
        ClothingmatchingRecyclerView = (RecyclerView) findViewById(R.id.Clothingmatching_RecyclerView);
        ClothingmatchingRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.VERTICAL));
        ClothingmatchingSmartRefreshLayout.setOnRefreshLoadMoreListener(this);
        presenter = new ClothingmatchingPresenter(this,new ClothingmatchingModel());
        presenter.clothing("Home_zidingyi.php");

    }

    @Override
    public void initDate() {

    }


    @Override
    public void getvier(List<ClothingmatchingBean.ShujuBean> dataBeans) {
        ClothingmatchingSmartRefreshLayout.finishLoadMore();
        ClothingmatchingSmartRefreshLayout.finishRefresh();
        if (adpter==null){
            adpter = new ClothingmatchingAdpter(dataBeans);
            ClothingmatchingRecyclerView.setAdapter(adpter);
        }else {
            if (issdd){
                adpter.getData().clear();
            }
            adpter.getData().addAll(dataBeans);
            adpter.notifyDataSetChanged();
        }
    }

    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        issdd =false;
        refreshLayout.finishLoadMore();
        refreshLayout.finishRefresh();
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        if (issdd){
            Log.i("aaa","la1");
        }
        refreshLayout.finishLoadMore();
        refreshLayout.finishRefresh();
    }


}
